import echarts from 'echarts';

const install = function (Vue) {
    Object.defineProperties(Vue.prototype, {
        $echarts: {
            get() {
                return {
                    chinaMap: function (id) {
                        let dom = document.getElementById(id);
                        let myChars = echarts.init(dom);
                        var option = {
                            tooltip: {

                            },
                            // backgroundColor: '#000', //整体背景
                            geo: {
                                map: 'china',
                                label: { //控制省份名
                                    normal: { //正常模式
                                        show: false
                                    },
                                    emphasis: { //hover模式
                                        show: true
                                    }
                                },
                                zoom: 1.2,
                                aspectScale: 0.75,
                                itemStyle: {
                                    normal: {
                                        areaColor: 'rgba(2,100,195,0.5)',
                                        borderColor: '#02d1fd',
                                        shadowOffsetX: 0,
                                        shadowOffsetY: 0,
                                        shadowBlur: 120,
                                        shadowColor: 'rgb(2,209,253,0.7)'
                                    }
                                }
                            },
                            series: [{
                                name: '省份',
                                showLegendSymbol: false,    // 存在legend时不显示
                                type: 'map',
                                map: 'china',
                                label: { //控制省份名
                                    normal: { //正常模式
                                        show: true
                                    },
                                    emphasis: { //hover模式
                                        show: true
                                    }
                                },
                                zoom: 1.2,
                                aspectScale: 0.75,
                                itemStyle: {
                                    normal: {
                                        areaColor: 'rgba(2,100,195,0.5)',
                                        borderColor: '#02d1fd',
                                    },
                                    emphasis: {
                                        areaColor: 'rgba(118,237,236,0.8)',
                                        shadowOffsetX: 0,
                                        shadowOffsetY: 0,
                                        shadowBlur: 20,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                },
                                zlevel: 1,
                                data: [
                                    {
                                        "name": "北京",
                                        "value": 395,
                                        "percent": "39.3%",
                                        itemStyle: {normal: {areaColor: '#f00'}}
                                    },
                                    {"name": "天津", "value": 17, "percent": "1.7%"},
                                    {"name": "上海", "value": 210, "percent": "20.9%"},
                                    {"name": "重庆", "value": 5, "percent": "0.5%"},
                                    {"name": "河北", "value": 0, "percent": "0%"},
                                    {"name": "河南", "value": 3, "percent": "0.3%"},
                                    {"name": "云南", "value": 0, "percent": "0%"},
                                    {"name": "辽宁", "value": 5, "percent": "0.5%"},
                                    {"name": "黑龙江", "value": 3, "percent": "0.3%"},
                                    {"name": "湖南", "value": 0, "percent": "0%"},
                                    {"name": "安徽", "value": 12, "percent": "1.2%"},
                                    {"name": "山东", "value": 10, "percent": "1%"},
                                    {"name": "新疆", "value": 0, "percent": "0%"},
                                    {"name": "江苏", "value": 42, "percent": "4.2%"},
                                    {"name": "浙江", "value": 66, "percent": "6.6%"},
                                    {"name": "江西", "value": 3, "percent": "0.3%"},
                                    {"name": "湖北", "value": 15, "percent": "1.5%"},
                                    {"name": "广西", "value": 0, "percent": "0%"},
                                    {"name": "甘肃", "value": 0, "percent": "0%"},
                                    {"name": "山西", "value": 0, "percent": "0%"},
                                    {"name": "内蒙古", "value": 0, "percent": "0%"},
                                    {"name": "陕西", "value": 17, "percent": "1.7%"},
                                    {"name": "吉林", "value": 0, "percent": "0%"},
                                    {"name": "福建", "value": 16, "percent": "1.6%"},
                                    {"name": "贵州", "value": 0, "percent": "0%"},
                                    {"name": "广东", "value": 165, "percent": "16.4%"},
                                    {"name": "青海", "value": 0, "percent": "0%"},
                                    {"name": "西藏", "value": 0, "percent": "0%"},
                                    {"name": "四川", "value": 20, "percent": "2%"},
                                    {"name": "宁夏", "value": 0, "percent": "0%"},
                                    {"name": "海南", "value": 0, "percent": "0%"},
                                    {"name": "台湾", "value": 0, "percent": "0%"},
                                    {"name": "香港", "value": 0, "percent": "0%"},
                                    {"name": "澳门", "value": 0, "percent": "0%"}
                                ]
                            }]
                        }
                        myChars.setOption(option);

                    },
                    revenueStatisticsLine(id) {
                        let dom = document.getElementById(id);
                        let myChart = echarts.init(dom);

                        // let arr1 = ["能源与节能", "材料", "先进制造与自动化", "电子信息", "其他"];
                        // let arr2 = [2234, 4448, 5142, 8442, 3132];
                        let option = {
                            xAxis: {
                                data: ['09-1', '09-2', '09-3', '09-4', '09-5']
                            },
                            yAxis: {},
                            series: [
                                {
                                    name:'订单数量',
                                    data: [10, 22, 28, 23, 19],
                                    type: 'line',
                                    smooth: true
                                },
                                {
                                    name:'金额',
                                    data: [10, 22, 19, 23, 19],
                                    type: 'line',
                                    smooth: true
                                }
                            ]
                        };
                        myChart.setOption(option, true);

                    },
                    renenuePie(id) {
                        let dom = document.getElementById(id);
                        let myChart = echarts.init(dom);
                        let option = {
                            title: {                     //标题
                                text: '订单状态分布数据',
                                left: 'center',
                                top:10,
                                textStyle: {
                                    color: '#fff'
                                }
                            },
                            tooltip: {
                                trigger: 'item',
                                formatter: "{b}: {c} ({d}%)"
                            },
                            labelLine: {
                                normal: {
                                    smooth: 0.2,
                                    length: 10,
                                    length2: 10
                                }
                            },
                            series: [
                                {
                                    type: 'pie',
                                    stillShowZeroSum: true,
                                    label: {
                                        show: true
                                    },
                                    data: [
                                        {
                                            value: 1000,
                                            name: '已支付'
                                        },
                                        {
                                            value: 300,
                                            name: '待支付'
                                        },
                                        {
                                            value: 100,
                                            name: '异常'
                                        },
                                        {
                                            value: 30,
                                            name: '售后'
                                        }
                                    ],
                                    animationType: 'scale',
                                    animationEasing: 'elasticOut'
                                }
                            ]
                        };
                        myChart.setOption(option, true);
                    },
                }
            }
        }
    })
}

export default install;